package com.ansys.demo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @Author: panghai
 * @Date: 2022/04/05/19:18
 * @Description: 为访问系统资源添加映射
 */
@Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter {

    @Value("${imagePathForWindow}")
    private String imagePathForWindow;

    @Value("${imagePathForLinux}")
    private String imagePathForLinux;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String os = System.getProperty("os.name").toLowerCase();
        if (os.startsWith("win")) {
            registry.addResourceHandler("/**").
                    addResourceLocations("file:"+imagePathForWindow);
        }else{//linux和mac系统
            registry.addResourceHandler("/**").
                    addResourceLocations("file:"+imagePathForLinux);
        }
    }
}
